#include <cstdio>
#include <cstring>
const int MAX_G = 105;
const int MAX_INT = 0x6F6F6F6F;

struct min_cost {
	int adjvex;
	int lowcost;
	min_cost(int v, int c):adjvex(v), lowcost(c) { }
	min_cost():adjvex(-1), lowcost(MAX_INT) { }
};

int N;
int G[MAX_G][MAX_G];
min_cost MC[MAX_G];
bool VIS[MAX_G];

int prim() {
	int route=0;
	for (int i=1; i<=N; i++) {
		MC[i] = min_cost(1, G[1][i]);
	}
	memset(VIS, 0, sizeof(VIS));
	VIS[1] = true;
	for (int i=1; i<N; i++) {
		int v, cost=MAX_INT;
		for (int j=1; j<=N; j++) {
			if (!VIS[j] && MC[j].lowcost < cost) {
				cost = MC[j].lowcost;
				v=j;
			}
		}
		route += cost;
		VIS[v] = true;
		for (int j=1; j<=N; j++) {
			if (!VIS[j] && G[v][j] < MC[j].lowcost) {
				MC[j].adjvex = v;
				MC[j].lowcost = G[v][j];
			}
		}
	}
	return route;
}

int main() {
	while (true) {
		scanf("%d", &N);
		if (N==0) break;
		memset(G, 0x6F, sizeof(G));
		for (int i=0; i<(N*(N-1)/2); i++) {
			int a, b, cost;
			scanf("%d%d%d", &a, &b, &cost);
			G[a][b] = cost;
			G[b][a] = cost;
		}
		int min = prim();
		printf("%d\n", min);
	}
	return 0;
}
